package com.skt.common_hr.welfare.model
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.approval.IRequestApprovalProxy;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.welfare.model.vo.ReqWelfareVO;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;

	public class WelfareApprovalProxy extends CommonProxy implements IRequestApprovalProxy
	{
		public static const NAME:String = "WelfareApprovalProxy";

		public var dataProvider:ReqWelfareVO;

		private var templateHTML:String = "";
		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function WelfareApprovalProxy(data:Object=null)
		{
			super(NAME, data);
			loadTemplate();
		}

		private var _key:String = "";
		public function get key():String
		{
			return _key;
		}
		public function set key(k:String):void
		{
			_key = k;
		}


		public function get title():String
		{
			var tmp:String = "선택적 복리후생 신청(";
			
			var day:String = dataProvider.UDATE_F;
			var howmuch:String = ', 신청금액:'+dataProvider.BNFAMT_F+'원)';
			return tmp + day + howmuch;
			
		}

		public function get content():String
		{
			return buildHTML(dataProvider);
		}

		public function get appCode():String
		{
			return "09"; 	//
		}


 		private function loadTemplate():void
		{
			var request:URLRequest = new URLRequest("assets/template/welfare.tmp");
			loader.addEventListener(Event.COMPLETE, templateResult);
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
		}

		private function templateResult(event:Event):void
		{
			templateHTML = loader.data;
		}

		private function ioErrorHandler(event:IOErrorEvent):void
		{
			trace("ioErrorHandler: " + event);
		}

 		private function buildHTML(vo:ReqWelfareVO):String
		{
			var htmlAll:String = templateHTML;
			var htmlBlock:String = "";

			var __ENAME__:RegExp  	= /__ENAME__/;
			var __IDATE__:RegExp  	= /__IDATE__/;
			var __UDATE__:RegExp  	= /__UDATE__/;
			var __BNFAMT__:RegExp  	= /__BNFAMT__/;
			var __CAFGTX__:RegExp  	= /__CAFGTX__/;
			var __CAFTX__:RegExp  	= /__CAFTX__/;
			var __COMNM__:RegExp  	= /__COMNM__/;						
			var __APGBN_TX__:RegExp = /__APGBN_TX__/;
			var __DTEXT__:RegExp  	= /__DTEXT__/;
			
			//htmlAll = htmlAll.replace(__ENAME__, vo.ENAME);
			htmlAll = htmlAll.replace(__ENAME__, Variables.myName);
			htmlAll = htmlAll.replace(__IDATE__, vo.IDATE_F);
			htmlAll = htmlAll.replace(__UDATE__, vo.UDATE_F);
			htmlAll = htmlAll.replace(__BNFAMT__, vo.BNFAMT_F+'원');
			htmlAll = htmlAll.replace(__CAFGTX__, vo.CAFGTX);
			htmlAll = htmlAll.replace(__CAFTX__, vo.CAFTX);
			htmlAll = htmlAll.replace(__COMNM__, vo.COMNM);
			htmlAll = htmlAll.replace(__APGBN_TX__, vo.APGBN_TX);
			htmlAll = htmlAll.replace(__DTEXT__, vo.DTEXT==null?'':vo.DTEXT);
//			if(vo.COSEL == 'X') {
//				htmlAll = htmlAll.replace(ptnCosten, vo.COSTEN);
//			} else {
//				htmlAll = htmlAll.replace(ptnCosten, '');
//			}
			return htmlAll;
		}
	}
}